package org.budo.cmbc.sdk.entity;

import java.util.ArrayList;
import java.util.List;

import org.budo.support.lang.util.ListUtil;
import org.budo.xml.XmlObject;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

/**
 * @author lmw
 */
@Getter
@Setter
@NoArgsConstructor
@Slf4j
public class QryDtlResponse extends AbstractCmbcResponse {
    private static final long serialVersionUID = -3350719882950496784L;

    private List<DtlInfo> dtlInfos;

    public QryDtlResponse(String responseXml) {
        this.setResponseBody(responseXml);

        XmlObject xDataBody = this.xDataBody(responseXml);

        if (null == xDataBody) {
            log.error("#34 xDataBody=" + xDataBody + ", responseXml=" + responseXml);
            return;
        }

        XmlObject dtlList = xDataBody.getChildNodeByName("dtlList");
        XmlObject[] dtlInfoArray = dtlList.getChildNodeArrayByName("dtlInfo");

        this.dtlInfos = new ArrayList<DtlInfo>(dtlInfoArray.length);

        for (XmlObject dtlInfoObject : dtlInfoArray) {
            DtlInfo dtlInfo = new DtlInfo(dtlInfoObject);
            this.dtlInfos.add(dtlInfo);
        }
    }

    @Override
    public String toString() {
        return super.toString() + ", dtlInfos.size=" + ListUtil.size(this.getDtlInfos());
    }
}